//脚本唯一关键字,通过该关键字找到对应脚本，每个脚本必须有该描述。
var v_script_id = 'authtree_1';
//脚本状态,0:该脚本不许执行，1:该脚本可以执行
var v_status = '1';

//脚本逻辑写在run语句之间
if (run){

	var user = action.getSession().getAttribute("user");
	if(user.getRolekind()<3){
		action.vars.put(action.V_TABLE_NAME,'h_auth_trees');//指定获取数据的表名
		action.vars.put(action.V_CONDITION, ' where state!=1 order by oid');
	}else{
		//action.vars.put(action.V_TABLE_NAME,'h_auth_trees');//指定获取数据的表名
		
		//SELECT distinct(a.id),a.* from (select  * FROM h_auth_trees CONNECT BY PRIOR pid = id START WITH id in(select authid from h_auth_role_infos where roleid in ( '201') union ( select authid from h_auth_user_infos where userid='81')) ) a where a.state!=1 order by a.oid;
	 	var tname = '';
		var t1 = '(select  * FROM h_auth_trees CONNECT BY PRIOR pid = id START WITH id in(select authid from v_auth_all where  ';
		if (user.getRoleids('roleid','or') == null){
			tname = t1 + 'userid in( '+ user.getId() +')) ) a';
		}else{
			tname = t1 + user.getRoleids('roleid','or') + ' or userid in( '+ user.getId() +')) ) a';
		}
		var col = ' distinct(a.id), a.pid, a.havecid, a.oid, a.alevel, a.title, a.kind, a.note, a.state';
		var where = ' where a.state!=1 order by a.oid';
		action.vars.put(action.V_TABLE_NAME,tname); 
		action.vars.put(action.V_COLUMNS,col); 
		action.vars.put(action.V_CONDITION, where);
	
	}
	
}